home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 9 / The PC-SIG Library on CD ROM - Ninth Edition.iso / 401_500 / DISK0443 / DISK0443.ZIP / TSCORE.S3I < prev    next >
Text File  |  1987-01-09  |  9KB  |  258 lines

  1.       program TSCORE
  2. c$
  3. c$    Compute weighted average of assignment and test scores, and the
  4. c$    T score where T = 10*((x-mu)/sigma) + 50, mu = mean, sigma =
  5. c$    standard deviation.
  6. c$
  7. c$    *****     Input     **********************************************
  8. c$
  9. c$    First is a line that is used as a page heading for all output.
  10. c$    This should not be enclosed in quotes.
  11. c$
  12. c$    Second is number of scores (integer) followed by pairs consisting
  13. c$    of possible score (integer) and weight (integer), all separated by
  14. c$    commas.
  15. c$
  16. c$    Remaining inputs each consist of student name in quotes
  17. c$    (character) followed by student ID number (integer) and all scores
  18. c$    (integer), with all quantities for each student separated by
  19. c$    commas.
  20. c$
  21. c$    Fortran list input is used.  Therefore, input for each student may
  22. c$    consist of as many lines as necessary.
  23. c$
  24. c$    Input is terminated by end-of-file.
  25. c$
  26. c$    *****     Output     *********************************************
  27. c$
  28. c$    Output consists of the input, with student scores augmented by the
  29. c$    weighted average of all scores, scaled onto 0% to 100% range
  30. c$    (identified by Raw% column heading), and the T score (identified
  31. c$    by T column heading).  This output is first printed in the order
  32. c$    submitted, and second printed in decreasing order of T scores.
  33. c$
  34. c$    *****     Parameters     *****************************************
  35. c$
  36. c$MXSCOR  is the maximum number of scores per student.  If this
  37. c$        parameter is made greater than 14 the Format statements in
  38. c$        procedure (print scores) must be changed.
  39. c$MXSTUD  is the maximum number of students.
  40. c$
  41.       parameter (MXSCOR=14)
  42.       parameter (MXSTUD=60)
  43. c$
  44. c$    *****     Variables     ********************************************
  45. c$
  46. c$DONE    is a signal that end-of-file is present in input.
  47. c$I       is a loop induction variable.
  48. c$ID      is the set of student identification numbers.
  49. c$INUNIT  is the unit number from which to read input.
  50. c$INWT    is the set of relative weights of assignments and
  51. c$        examinations.
  52. c$J       is a loop induction variable.
  53. c$K       is a loop induction variable.
  54. c$LINE    is a line of input, containing an input or output file name.
  55. c$MU      is the mean of composite scores in the RAW vector.
  56. c$MUS     is an array of means of columns of SCORES.
  57. c$NBLANK  is the number of blanks required to center a column heading in
  58. c$        procedure (print scores).
  59. c$NSCORE  is the number of scores per student (assignments and
  60. c$        examinations.
  61. c$NSTDNT  is the number of students.
  62. c$OTUNIT  is the unit number on which to write output.
  63. c$P       is a permutation vector used to sort results into descending
  64. c$        order by T score.
  65. c$PAGHDG  is printed as a page heading for output.
  66. c$RAW     is the set of weighted scores, one per student.  The RAW score
  67. c$        for a student is the weighted average of all assignment and
  68. c$        examination scores.
  69. c$SCORES  is the set of all scores.
  70. c$SIGMA   is the unbiased standard deviation of the RAW scores.
  71. c$SIGMAS  is an array of standard deviations of columns of SCORES.
  72. c$SNAME   is the set of student names.
  73. c$SUMWT   is the sum of weights of assignments and examinations.  See
  74. c$        WEIGHT below for explanation of use of SUMWT.
  75. c$T       is the set of T scores.
  76. c$TOP     is the set of maximum possible scores for assignments and
  77. c$        examinations.
  78. c$TT      is a value of T, used while sorting results by descending
  79. c$        order of T scores.
  80. c$WEIGHT  is the set of weights of assignments.  WEIGHT is used in
  81. c$        calculating the RAW score for each student.  WEIGHT(I) is
  82. c$        INWT(I) / (SUMWT * TOP(I)), where all arithmetic is performed
  83. c$        in floating point.  The inner product of TOP and WEIGHT is 1,
  84. c$        and therefore all elements of RAW are between 0 and 1.
  85. c$
  86.       character*80 PAGHDG
  87.       character*30 SNAME(MXSTUD)
  88.       integer I,ID(MXSTUD),INWT(MXSCOR),INUNIT,J,K
  89.       character*80 LINE
  90.       integer NBLANK,NSCORE,NSTDNT,OTUNIT
  91.       integer P(MXSTUD),SCORES(MXSTUD,MXSCOR),SUMWT,TOP(MXSCOR)
  92.       logical DONE
  93.       real MU,MUS(MXSCOR),RAW(MXSTUD),SIGMA,SIGMAS(MXSCOR),T(MXSTUD)
  94.       real TT,WEIGHT(MXSCOR)
  95. c$
  96.       parameter (INUNIT=10, OTUNIT=11)
  97. c$
  98. c$    *****     Procedures     *****************************************
  99. c$
  100. c$    Open input file.
  101. c$
  102.       do forever
  103.          print *,'Enter input file name, or CON: for input from the'
  104.          print *,'keyboard: '
  105.          read (*,'(a80)') line
  106.          open (inunit,file=line,err=200)
  107.          exit forever
  108. 200      print *,'Unable to open input file.  Try again? '
  109.          read (*,'(a80)') line
  110.          if (line(1:1).eq.'n'.or.line(1:1).eq.'N') stop
  111.       end forever
  112. c$
  113. c$    Open output file.
  114. c$
  115.       do forever
  116.          print *,'Enter output file name, PRN: for output to the'
  117.          print *,'printer, or CON: for output to the console: '
  118.          read (*,'(a80)') line
  119.          open (otunit,file=line,err=210,carriage control='FORTRAN')
  120.          exit forever
  121. 210      print *,'Unable to open output file.  Try again? '
  122.          read (*,'(a80)') line
  123.          if (line(1:1).eq.'n'.or.line(1:1).eq.'N') stop
  124.       end forever
  125. c$
  126. c$    Read the page heading.
  127. c$
  128.       read (inunit,'(a80)') paghdg
  129. c$
  130. c$    Read number of scores, followed by possible score and weight for
  131. c$    each assignment.
  132. c$
  133.       read (inunit,*) nscore, (top(i),inwt(i), i=1, nscore)
  134. c$
  135. c$    Calculate sum of input weights.
  136. c$
  137.       sumwt=0
  138.       do for i = 1, nscore
  139.          sumwt=sumwt+inwt(i)
  140.       end for
  141. c$
  142. c$    Calculate weight = inwt /(top * sum of inwt).  Dividing by top
  143. c$    here saves dividing by top when calculating raw scores.
  144. c$
  145.       do for i = 1, nscore
  146.          weight(i) = float(inwt(i))/float(top(i)*sumwt)
  147.       end for
  148. c$
  149. c$    Make the averages for each assignment (MUS) zero.  The total of
  150. c$    scores for each assignment will be accumulated in MUS, and then
  151. c$    divided by the number of students to calculate the averages.
  152. c$
  153.       do for i = 1, nscore
  154.          mus(i) = 0.0
  155.       end for
  156. c$
  157. c$    Read scores for each student.  Compute the raw score and
  158. c$    accumulate the sum of raw scores to compute the mean.
  159. c$
  160.       mu=0.0
  161.       nstdnt=0
  162.       do forever
  163.       nstdnt=nstdnt+1
  164.       read (inunit,*,done=end) sname(nstdnt), id(nstdnt)
  165.      1,                        (scores(nstdnt,i), i=1, nscore)
  166.       if (done) exit forever
  167.       raw(nstdnt)=0.0
  168.       do for i = 1, nscore
  169.          raw(nstdnt) = raw(nstdnt) + float(scores(nstdnt,i))*weight(i)
  170.          mus(i) = mus(i) + float(scores(nstdnt,i))
  171.       end for
  172.       mu = mu + raw(nstdnt)
  173.       end forever
  174.       nstdnt = nstdnt - 1
  175.       if (nstdnt.eq.0) then
  176.          print *,' No student scores submitted'
  177.          stop
  178.       end if
  179.       if (nstdnt.eq.1) then
  180.          print *,' Scores for only one student submitted'
  181.          stop
  182.       end if
  183.       mu = mu/float(nstdnt)
  184. c$
  185. c$    Compute MUS and SIGMAS.
  186. c$
  187.       do for i = 1, nscore
  188.          mus(i) = mus(i)/float(nstdnt)
  189.          sigmas(i) = 0.0
  190.          do for j = 1, nstdnt
  191.             sigmas(i) = sigmas(i) + (float(scores(j,i))-mus(i))**2
  192.          end for
  193.          sigmas(i) = sqrt(sigmas(i)/(nstdnt-1))
  194.       end for
  195. c$
  196. c$    Compute sigma.
  197. c$
  198.       sigma=0.0
  199.       do for i = 1, nstdnt
  200.          sigma = sigma + (raw(i)-mu)**2
  201.       end for
  202.       sigma = sqrt(sigma/(nstdnt-1))
  203. c$
  204. c$    Compute T scores.
  205. c$
  206.       do for i = 1, nstdnt
  207.          t(i) = 10.0*(raw(i)-mu)/sigma+50.0
  208.          p(i) = i
  209.       end for
  210. c$
  211. c$    Print results, sort into descending order of T scores, print
  212. c$    results again.
  213. c$
  214.       nblank = (5*nscore-27)/2
  215.       do (print scores)
  216.       do for k = 2, nstdnt
  217.          tt = t(p(k))
  218.          do for j = 1, k-1
  219.             if (tt.gt.t(p(j))) then
  220.                i = p(k)
  221.                p(k) = p(j)
  222.                p(j) = i
  223.                tt = t(i)
  224.             end if
  225.          end for
  226.       end for
  227.       do (print scores)
  228. c$
  229.       write (otunit,'(''1'')')
  230.       stop
  231. c$
  232. c$
  233.       procedure (print scores)
  234.       write (otunit,10) paghdg
  235. 10    format ('1',a80)
  236.       write (otunit,20) (' ',i=1,nblank),' Homework and Examinations '
  237. 20    format (t50,70a)
  238.       write (otunit,30) (top(i), i = 1, nscore)
  239. 30    format (t31,'Possible score',t50,14i5)
  240.       write (otunit,40) (inwt(i), i = 1, nscore)
  241. 40    format (t31,'Weight',t50,14i5)
  242.       write (otunit,50) ('-----', i = 1, nscore)
  243. 50    format ('0Student name',t31,'   ID  Raw%   T',t50,14a5)
  244.       write (otunit,'()')
  245.       do for k = 1, nstdnt
  246.          i = p(k)
  247.          write (otunit,60) sname(i),id(i),raw(i),t(i)
  248.      1,                    (scores(i,j),j=1,nscore)
  249. 60       format (1x,a30,i5,2pf5.1,0pf5.1,t50,14i5)
  250.       end for
  251.       write (otunit,70) mu,(mus(i),i=1,nscore)
  252. 70    format ('0Mean',t37,2pf5.1,t51,0p14f5.0)
  253.       write (otunit,80) sigma,(sigmas(i),i=1,nscore)
  254. 80    format (' Standard Deviation',t37,2pf5.1,t51,0p14f5.1)
  255.       end procedure
  256. c$
  257.       end program
  258.